package cn.acrdpm.service;

import cn.acrdpm.entity.MsgLogKey;
import cn.acrdpm.entity.MsgLogWithBLOBs;
import cn.acrdpm.mapper.MsgLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Date;
import java.util.List;

@Service
public class MsgLogServiceImpl implements MsgLogService{

    @Autowired
    MsgLogMapper msgLogMapper;

    @Override
    public void updateStatus(String msgId, Integer status) {
        msgLogMapper.updateStatus(msgId,status);
    }

    @Override
    public MsgLogWithBLOBs selectByMsgId(String msgId) {
        if (!ObjectUtils.isEmpty(msgId)){
            return msgLogMapper.selectByPrimaryKey(new MsgLogKey(msgId));
        }
        return null;
    }

    @Override
    public List<MsgLogWithBLOBs> selectTimeoutMsg() {
        return msgLogMapper.selectTimeOutMsg();
    }

    @Override
    public void updateTryCount(String msgId, Integer tryCount) {
        MsgLogWithBLOBs msgLog = new MsgLogWithBLOBs();
        msgLog.setMsgId(msgId);
        msgLog.setTryCount(tryCount);
             msgLogMapper.updateByPrimaryKey(msgLog);
    }
}
